import numpy as np


def generate_time_sequence(trajectory, speed, pixel_size=10, interval_m=100):
    time_sequence = []
    t = 0

    for i in range(len(trajectory) - 1):
        start = np.array(trajectory[i], dtype=float)
        end = np.array(trajectory[i + 1], dtype=float)

        # 计算像素距离和实际距离
        dist_px = np.linalg.norm(end - start)
        dist_m = dist_px * pixel_size

        # 计算段内应插值多少点（每100米一个）
        num_points = max(1, int(np.floor(dist_m / interval_m)))

        for step in range(num_points):
            alpha = step / num_points
            pos = (1 - alpha) * start + alpha * end
            x, y = int(round(pos[0])), int(round(pos[1]))
            # 每段间隔的时间
            dt = (interval_m / speed)
            time_sequence.append((int(round(t)), x, y, speed))
            t += dt

    # 添加最后终点
    final_x, final_y = trajectory[-1]
    time_sequence.append((int(round(t)), int(final_x), int(final_y), speed))

    return time_sequence
